package com.dragon.logical.service.finance.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.common.model.ResultCode;
import com.dragon.common.model.exception.CustomException;
import com.dragon.logical.service.finance.IBillService;
import com.dragon.repository.config.annotation.DataScope;
import com.dragon.repository.entity.*;
import com.dragon.repository.mapper.*;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * <p>
 * 账单表 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-12-12
 */
@Service
public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IBillService {

    @Autowired
    BillMapper billMapper;
    @Autowired
    BillPlanMapper billPlanMapper;
    @Autowired
    BillCustomerMapper billCustomerMapper;
    @Autowired
    PlanCollectMapper planCollectMapper;
    @Autowired
    CustomerPaymentMapper customerPaymentMapper;
    @Autowired
    QuotesMapper quotesMapper;
    @Autowired
    QuotesProductsMapper quotesProductsMapper;
    @Autowired
    ContractMapper contractMapper;
    @Autowired
    PaymentContractMapper paymentContractMapper;

    @Autowired
    CustomerMapper customerMapper;

    @Override
    @DataScope(adminAlias = "M", adminField = "customerAdminId", deptAlias = "M", deptField = "customerDepartmentId")
    public Page<Bill> billList(Integer page ,Integer limit, Integer customerId, Integer isFinish,String time){
        Page<Bill> page1 = new Page<>(page, limit);
        QueryWrapper<Bill> wrapper = new QueryWrapper<>();
        wrapper.eq(customerId != null, "M.customer_id", customerId)
                .eq(isFinish != null, "M.is_finish", isFinish)
//                .eq(customerAdminId != null, "M.customerAdminId", customerAdminId)
                .apply(StrUtil.isNotBlank(time),"left(M.end_time, 7) = '"+time+"'")
                .orderByDesc("M.create_time");
        Page<Bill> billPage = billMapper.selectPageByWrapper(page1,wrapper);
        return billPage;
    }

    @Override
    public Page<PlanCollect> planCollects(Integer page, Integer limit, Integer customerId, String startTime, String endTime){
        Page<PlanCollect> page1 = new Page<>(page, limit);
        QueryWrapper<PlanCollect> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(PlanCollect::getCustomerId, customerId)
                .eq(PlanCollect::getBillStatus, 0)
                .eq(PlanCollect::getPlanPayType,0)
                .eq(PlanCollect::getDeleted,0)
                //.eq(PlanCollect::getSettlementType, 2)
                .ge(PlanCollect::getCreateTime, DateUtil.offsetDay(DateUtil.parse(startTime,"yyyy-MM-dd"), -1))
                .le(PlanCollect::getCreateTime, DateUtil.offsetDay(DateUtil.parse(endTime,"yyyy-MM-dd"), 1));
        Page<PlanCollect> planCollectPage = planCollectMapper.selectPage(page1, wrapper);
        planCollectPage.getRecords().forEach(planCollect -> {
            Contract contract = contractMapper.selectById(planCollect.getContractId());
            planCollect.setTractName(contract.getName());
        });
        return planCollectPage;
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void addBill(Bill bill){
        //判断当前对账单是否存在 存在就更新
        List<Bill> bill1 = billMapper.selectList(new QueryWrapper<Bill>()
                .lambda().eq(Bill::getCustomerId, bill.getCustomerId()));
        if(bill1.size() > 0){
            bill1.forEach(bill2 -> {
                boolean b = belongCalendar(bill.getStartTime(),bill.getEndTime(), bill2.getStartTime(), bill2.getEndTime());
                //boolean b1 = belongCalendar(bill.getStartTime(),bill.getEndTime(), bill2.getStartTime(), bill2.getEndTime());
                if (!b){
                    throw new CustomException(ResultCode.FINANCE_BILL_IS_NOT_FOUND);
                }
            });
        }
        //添加对账单主表
//        DateTime newDate2 = DateUtil.offsetDay(bill.getEndTime(), 1);
//        bill.setEndTime(en);
        bill.setCreateTime(DateUtil.date());
        billMapper.insert(bill);
        //查询时间段的计划收款
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper<PlanCollect> wrapper = new QueryWrapper<>();
        wrapper.eq("M.customer_id", bill.getCustomerId())
                .eq("M.deleted",0)
                .eq("M.bill_status", 0)
                .eq("M.plan_status",0)
                .between("M.order_time",DateUtil.format(bill.getStartTime(),"yyyy-MM-dd"),DateUtil.format(bill.getEndTime(),"yyyy-MM-dd"));

        //获取应收账单中在回款，但是没点击确认的单子，如果有则不生成账单
        List<PlanCollect> planCollects1 = planCollectMapper.selectPaymentIds(wrapper);

        wrapper.notIn(planCollects1.size()!=0,"M.id",planCollects1.stream().map(PlanCollect::getId).collect(Collectors.toList()));

        List<PlanCollect> planCollects = planCollectMapper.selectPlanByOrderTime(wrapper);
        //应收
        AtomicReference<Double> planMoney = new AtomicReference<>(Double.valueOf(0));
        //实收
        AtomicReference<Double> paymentMoney = new AtomicReference<>(Double.valueOf(0));
        if(planCollects.size() > 0){
            planCollects.forEach( planCollect ->  {
                //添加子表
                BillPlan billPlan = new BillPlan();
                billPlan.setBillId(bill.getId());
                billPlan.setPlanId(planCollect.getId());
                billPlan.setCreateTime(DateUtil.date());
                billPlanMapper.insert(billPlan);

                //修改计划收款表信息
                planCollect.setBillStatus(1);
                planCollect.setBillId(bill.getId());
                planCollectMapper.updateById(planCollect);

                if (planCollect.getPlanMoney() != null || planCollect.getPlanMoney() != 0.00){
                    planMoney.updateAndGet(v -> v + planCollect.getPlanMoney() - planCollect.getRefundMoney());
                }
                if (planCollect.getActualPlanMoney() != null || planCollect.getActualPlanMoney() != 0.00){
                    paymentMoney.updateAndGet(v -> v + planCollect.getActualPlanMoney());
                }
                PaymentContract paymentContract = new PaymentContract();
                paymentContract.setBillId(bill.getId());
                paymentContractMapper.update(paymentContract,new QueryWrapper<PaymentContract>()
                        .lambda().eq(PaymentContract::getPlanId,planCollect.getId()));

            });
        }

        bill.setPlanMoney(planMoney.get());
        bill.setPaymentMoney(paymentMoney.get());
        bill.setBalanceMoney(planMoney.get() - paymentMoney.get());
        if(bill.getBalanceMoney().equals(0.00) && planCollects1.size()==0){
            bill.setIsFinish(1);
        }
        billMapper.updateById(bill);
        
        //判断账单总金额存在
        QueryWrapper<BillCustomer> wrapper1 = new QueryWrapper<>();
        wrapper1.lambda().eq(BillCustomer::getCustomerId, bill.getCustomerId());
        BillCustomer billCustomer = billCustomerMapper.selectOne(wrapper1);
        if (billCustomer == null) {
            BillCustomer billCustomer1 = new BillCustomer();
            billCustomer1.setAccruedPlanMoney( bill.getPlanMoney());
            billCustomer1.setAccruedPaymentMoney(bill.getPaymentMoney());
            billCustomer1.setCustomerId(bill.getCustomerId());
            billCustomer1.setCreateTime(DateUtil.date());
            billCustomerMapper.insert(billCustomer1);
        } else {
            billCustomer.setAccruedPlanMoney(billCustomer.getAccruedPlanMoney() + bill.getPlanMoney());
            billCustomer.setAccruedPaymentMoney(billCustomer.getAccruedPaymentMoney()+bill.getPaymentMoney());
            billCustomer.setUpdateTime(DateUtil.date());
            billCustomerMapper.updateById(billCustomer);
        }
    }

    @Override
    public boolean belongCalendar(Date startTime,Date endTime, Date historyStartTime,
                                         Date historyEndTime) {
        Calendar start = Calendar.getInstance();
        start.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        Calendar historyStart = Calendar.getInstance();
        historyStart.setTime(historyStartTime);

        Calendar historyEnd = Calendar.getInstance();
        historyEnd.setTime(historyEndTime);

        if(start.compareTo(historyStart) < 0 && start.compareTo(historyEnd) < 0 && end.compareTo(historyStart) < 0 && end.compareTo(historyEnd) < 0){
            return true;
        }

        if(start.compareTo(historyStart) > 0 && start.compareTo(historyEnd) > 0 && end.compareTo(historyStart) > 0 && end.compareTo(historyEnd) > 0){
            return true;
        }
        return false;
    }



    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void update(Integer billId){
        Bill bill = billMapper.selectById(billId);
        QueryWrapper<PlanCollect> wrapper = new QueryWrapper<>();
        wrapper.eq("M.customer_id", bill.getCustomerId())
                .eq("M.bill_status", 0)
                .eq("M.plan_status",0)
                .eq("M.deleted", 0)
                .between("M.order_time",DateUtil.format(bill.getStartTime(),"yyyy-MM-dd"),DateUtil.format(bill.getEndTime(),"yyyy-MM-dd"));

        //获取应收账单中在回款，但是没点击确认的单子，如果有则不生成账单
        List<PlanCollect> planCollects1 = planCollectMapper.selectPaymentIds(wrapper);

        wrapper.notIn(planCollects1.size()!=0,"M.id",planCollects1.stream().map(PlanCollect::getId).collect(Collectors.toList()));

        List<PlanCollect> planCollects = planCollectMapper.selectPlanByOrderTime(wrapper);

        //应收
        AtomicReference<Double> planMoney = new AtomicReference<>(Double.valueOf(0));
        //实收
        AtomicReference<Double> paymentMoney = new AtomicReference<>(Double.valueOf(0));
        if (planCollects.size() == 0){
            throw new CustomException(ResultCode.BILL_IS_NOT_DATA_UPDATE);
        }
        planCollects.forEach( planCollect ->  {
            //添加子表
            BillPlan billPlan = new BillPlan();
            billPlan.setBillId(bill.getId());
            billPlan.setPlanId(planCollect.getId());
            billPlan.setCreateTime(DateUtil.date());
            billPlanMapper.insert(billPlan);

            //修改计划收款表信息
            planCollect.setBillStatus(1);
            planCollect.setBillId(bill.getId());
            planCollectMapper.updateById(planCollect);

            planMoney.updateAndGet(v -> v + planCollect.getPlanMoney());
            paymentMoney.updateAndGet(v -> v + planCollect.getActualPlanMoney());
        });

        // 查询所有单子是否已经回款完毕
        List<BillPlan> billPlans = billPlanMapper.selectList(new LambdaQueryWrapper<BillPlan>().eq(BillPlan::getBillId,bill.getId()));

        //获取所有单子是否回款完毕
        if(billPlans.size()>0){
            List<PlanCollect> planCollects2 = planCollectMapper.selectList(
                    new LambdaQueryWrapper<PlanCollect>()
                            .in(PlanCollect::getId,billPlans.stream().map(BillPlan::getPlanId).collect(Collectors.toList()))
                            .eq(PlanCollect::getPlanStatus,0)
            );

            if(planCollects2.size() == 0){
                bill.setIsFinish(1);
            }
        }

        bill.setPlanMoney(bill.getPlanMoney() + planMoney.get());
        bill.setPaymentMoney(bill.getPaymentMoney() + paymentMoney.get());
        bill.setBalanceMoney(bill.getPlanMoney() - bill.getPaymentMoney());
        bill.setIsFinish(0);
        billMapper.updateById(bill);

        //判断账单总金额存在
        QueryWrapper<BillCustomer> wrapper1 = new QueryWrapper<>();
        wrapper1.lambda().eq(BillCustomer::getCustomerId, bill.getCustomerId());
        BillCustomer billCustomer = billCustomerMapper.selectOne(wrapper1);
        if (billCustomer != null) {
            billCustomer.setAccruedPlanMoney(bill.getPlanMoney());
            billCustomer.setAccruedPaymentMoney(bill.getPaymentMoney());
            billCustomer.setUpdateTime(DateUtil.date());
            billCustomerMapper.updateById(billCustomer);
        }

    }

    @Override
    public Bill detailOne(Integer billId){
        //"合同编码","合同名称","日期","合同金额","产品名称", "规格型号", "材质", "数量","单位"
        Bill bill = billMapper.selectBillOne(billId);
        List<PlanCollect> planCollects = planCollectMapper.selectList(new QueryWrapper<PlanCollect>().lambda()
                .eq(PlanCollect::getBillId, billId).eq(PlanCollect::getPlanPayType,0));
        //bill.setPlanCollects(planCollects);
        //获取合同id 合同信息
        List<Integer> contractIds = planCollects.stream().map(PlanCollect::getContractId).collect(Collectors.toList());
//        List<Contract> contracts = contractMapper.selectList(new QueryWrapper<Contract>()
//                .lambda()
//                .select(Contract::getId,Contract::getNum, Contract::getName, Contract::getOrderTime, Contract::getQuotesId)
//                .in(Contract::getId, contractIds));
        QueryWrapper<QuotesProducts> wrapper = new QueryWrapper<>();
        wrapper.in("N.id",contractIds);
        List<QuotesProducts> quotesProductsList  = quotesProductsMapper.selectContractAndProductsListInQuotesId(wrapper);
        bill.setQuotesProductsList(quotesProductsList);
        return bill;
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void updateBillCustomer(CustomerPayment customerPayment){

        //修改本期账单的收款金额
        List<PaymentContract> paymentContracts = paymentContractMapper.selectList(new QueryWrapper<PaymentContract>()
                .lambda().eq(PaymentContract::getPaymentId, customerPayment.getId()));
        paymentContracts.forEach(paymentContract -> {
            Bill bill = billMapper.selectById(paymentContract.getBillId());
            Double totalMoney = bill.getPaymentMoney() + paymentContract.getMoney();
            if(paymentContract.getBalancingAccounts() == 0){
                if (totalMoney.equals(bill.getPlanMoney())){
                    bill.setIsFinish(1);
                }
            } else {
                //bill.setBalanceMoney(bill.getPlanMoney() - totalMoney);
                bill.setIsFinish(1);
            }
            bill.setPaymentMoney(totalMoney);
            bill.setBalanceMoney( bill.getPlanMoney() - totalMoney );
            billMapper.updateById(bill);

            //修改累计账单的金额
            BillCustomer billCustomer = billCustomerMapper.selectOne(new QueryWrapper<BillCustomer>()
                    .lambda().eq(BillCustomer::getCustomerId, bill.getCustomerId()));
            billCustomer.setAccruedPaymentMoney(billCustomer.getAccruedPaymentMoney() + totalMoney);
            billCustomerMapper.updateById(billCustomer);
        });
    }

    @Override
    public void export(Integer id, HttpServletResponse response) throws UnsupportedEncodingException {
        Bill bill = detailOne(id);
        List<PlanCollect> planCollects = planCollectMapper.selectList(new QueryWrapper<PlanCollect>().lambda()
                .eq(PlanCollect::getBillId, id).eq(PlanCollect::getPlanPayType,0));
        //获取客户信息
        Customer customer = customerMapper.selectById(bill.getCustomerId());
        List<Integer> contractIds = planCollects.stream().map(PlanCollect::getContractId).collect(Collectors.toList());
        List<Contract> contracts = contractMapper.selectList(new QueryWrapper<Contract>().lambda().in(Contract::getId, contractIds));
        List<Integer> quotesIds = contracts.stream().map(Contract::getQuotesId).collect(Collectors.toList());
//        QueryWrapper<QuotesProducts> wrapper = new QueryWrapper<>();
//        wrapper.lambda().in(QuotesProducts::getQuotesId,quotesIds);
//        List<QuotesProducts> quotesProducts = quotesProductsMapper.selectProductsListInQuotesId(wrapper);

        ExcelWriter writer = ExcelUtil.getWriter();
        writer.passCurrentRow();

        writer.setColumnWidth(-1,15);
//        writer.setRowHeight(-1,25);

        // 获得表头单元格样式对象
        CellStyle headCellStyle = writer.getHeadCellStyle();
        // 设置表头前景色
        //headCellStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
        // 创建字体样式
        Font headCellFont = writer.createFont();
        // 设置字体颜色
        // headCellFont.setColor(IndexedColors.DARK_RED.index);
        // 设置字体大小
        headCellFont.setFontHeightInPoints((short) 18);
        // 设置字体类型
        headCellFont.setFontName("Microsoft YaHei UI");
        // 设置字体加粗
        headCellFont.setBold(true);
        // 设置斜体
        headCellFont.setItalic(true);
        // 设置删除线
//        headCellFont.setStrikeout(true);
        headCellStyle.setFont(headCellFont);

        CellStyle cellStyle = writer.getCellStyle();

        cellStyle.setAlignment(HorizontalAlignment.LEFT);


        writer.merge(0,0,0,8, customer.getCustomerName()
                .concat(DateUtil.format(bill.getStartTime(), "yyyy-MM-dd"))
                .concat("--")
                .concat(DateUtil.format(bill.getEndTime(), "yyyy-MM-dd"))
                .concat("对账单"),true);
        //writer.setColumnWidth(-1,20);
        writer.setRowHeight(0,40);

        writer.createRowStyle(1).setAlignment(HorizontalAlignment.CENTER);
        List<String> row1 = CollUtil.newArrayList("合同编码","合同名称","日期","合同金额","产品名称", "规格型号", "材质", "数量","单位");
        //为数据表格填充样式
        writer.writeRow(row1);
        writer.setRowHeight(1,25);
//        List<List<String>> rowTotal = new ArrayList<>();
//        List<String> row1 = CollUtil.newArrayList("合同编码","合同名称","合同金额","日期","产品名称", "规格型号", "材质", "数量","单位");
//        rowTotal.add(row1);
        QueryWrapper<QuotesProducts> wrapper = new QueryWrapper<>();
        AtomicReference<Integer> size = new AtomicReference<>(2);
        AtomicReference<Integer> sizes = new AtomicReference<>(2);
        quotesIds.forEach(quotesId ->{
            wrapper.clear();
            wrapper.lambda().eq(QuotesProducts::getQuotesId,quotesId);
            List<QuotesProducts> quotesProducts = quotesProductsMapper.selectProductsListInQuotesId(wrapper);
            //合同信息
            Contract contract = contractMapper.selectOne(new LambdaQueryWrapper<Contract>().eq(Contract::getQuotesId,quotesId));
            quotesProducts.forEach(quotesProducts1 -> {
                Double contractMoney = contract.getMoney()-contract.getRefundMoney();
                //查询合同编码以及日期
                List<String> row = CollUtil.newArrayList(
                        contract.getNum(),contract.getName(),DateUtil.format(contract.getOrderTime(),"yyyy-MM-dd"),contractMoney.toString(),
                        quotesProducts1.getName(),quotesProducts1.getSpecification(),
                        quotesProducts1.getMaterial(),quotesProducts1.getNum().toString(),quotesProducts1.getUnitName());
                writer.writeRow(row);
                writer.setRowHeight(sizes.get(),25);
                sizes.set(sizes.get()+1);
            });
            if(quotesProducts.size() > 1){
                writer.merge(size.get(),size.get() + quotesProducts.size() - 1,0,0,contract.getNum(),false);
                writer.merge(size.get(),size.get() + quotesProducts.size() - 1,1,1,contract.getName(),false);
                writer.merge(size.get(),size.get() + quotesProducts.size() - 1,2,2,DateUtil.format(contract.getOrderTime(),"yyyy-MM-dd"),false);
                writer.merge(size.get(),size.get() + quotesProducts.size() - 1,3,3,contract.getMoney(),false);
            }
            size.set( size.get() + quotesProducts.size());
        });
        //获取上期数据
        Bill bill1 = billMapper.selectOne(new LambdaQueryWrapper<Bill>().lt(Bill::getId,bill.getId()).orderByDesc(Bill::getId).eq(Bill::getCustomerId,bill.getCustomerId()).last("limit 1"));
        Double money = 0.00;
        if(bill1 != null){
            money = bill1.getPlanMoney()-bill1.getPaymentMoney();
        }
        writer.merge(size.get(), size.get(),  0, 1, "上期未付款", false);
        writer.merge(size.get(), size.get(),  2, 4, String.format("￥%.2f",money), false);
        writer.merge(size.get(), size.get(),  5, 6, "本期合计", false);
        writer.merge(size.get(), size.get(),  7, 8, String.format("￥%.2f",bill.getPlanMoney()), false);
        writer.setRowHeight(size.get(),25);

        writer.merge(size.get() + 1, size.get() + 1,  0, 1, "本期实收", false);
        writer.merge(size.get() + 1, size.get() + 1,  2, 4, String.format("￥%.2f",bill.getPaymentMoney()), false);
        writer.merge(size.get() + 1, size.get() + 1,  5, 6, "累计欠款", false);
        writer.merge(size.get() + 1, size.get() + 1,  7, 8, String.format("￥%.2f",bill.getAccruedPlanMoney()-bill.getAccruedPaymentMoney()), false);
        writer.setRowHeight(size.get()+1,25);

        writer.merge(size.get() + 2,size.get() + 2,  0, 8,"账户名称: 杭州冠宇三维打印科技有限公司",false);
        writer.setRowHeight(size.get()+2,25);

        writer.merge(size.get() + 3,size.get() + 3,  0, 8,"开户行及账号：余杭农商行运河支行  201000336757071",false);
        writer.setRowHeight(size.get()+3,25);


        writer.merge(size.get() + 4,size.get() + 4,  0, 8,"                 供方:(签名盖公章)                                                                                     客户:《签名盖公章)",false);
        writer.setRowHeight(size.get()+4,25);


        writer.merge(size.get() + 5,size.get() + 5,  0, 8,"备注：1、如客户核对无误，请签字盖章确认;如不相符请注明差异并签章;谢谢!",false);
        writer.setRowHeight(size.get()+5,25);

        writer.merge(size.get() + 6,size.get() + 6,  0, 8,"         2、电子扫描件与原件同具法律效力",false);
        writer.setRowHeight(size.get()+6,25);

        writer.merge(size.get() + 7,size.get() + 7,  0, 8,"         3、双方之间的纠纷如无法协商解决，任何一方均可按照《合同法》的相关规定确定管辖地。",false);
        writer.setRowHeight(size.get()+7,25);


        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-Disposition","attachment;filename=test.xls");
        ServletOutputStream out = null;
        try {
            out = response.getOutputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        writer.flush(out, true);
// 关闭writer，释放内存
        writer.close();
//此处记得关闭输出Servlet流
        IoUtil.close(out);
    }


    @Override
    public Map<String, Object> billStatistics(Integer customerId) {
        QueryWrapper<Bill> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(customerId != null, Bill::getCustomerId, customerId);
        Double paymentMoney = billMapper.selectPaymentMoney(wrapper);
        //统计所有实收 应收
        Double planMoney = billMapper.selectPlanMoney(wrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("paymentTotal", paymentMoney);
        map.put("planTotal", planMoney);
        return map;
    }
}
